//package com.central.apps.controller;
//
//import com.central.app.service.HandlerService;
//import org.apache.commons.collections.CollectionUtils;
//import org.apache.commons.collections.MapUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.List;
//import java.util.Map;
////采购申请变更保存按钮
//@RestController
//public class ChangeBaTreasuryController {
//    @Autowired
//    private HandlerService handlerService;
//    @PostMapping("/afterChangeBaTreasury")
//    //平衡利库返回子表库存余量
//    private void afterChangeBaTreasury(@RequestParam Integer prcid, @RequestParam Integer id1) throws Exception {
//        List<Map<String, Object>> sys_setting = handlerService.findBySql("select field8 from sys_setting");//系统设置表
//        if (CollectionUtils.isNotEmpty(sys_setting)){
//            String field8 = MapUtils.getString(sys_setting.get(0), "field8");
//            if (field8.equals("1")){
//                List<Map<String, Object>> bySql = handlerService.findBySql("select subjectno from gq_prchange where id='" + prcid + "'");
//                if (CollectionUtils.isNotEmpty(bySql)){
//                    String subjectno = MapUtils.getString(bySql.get(0), "subjectno");
//                    List<Map<String, Object>> bySql1 = handlerService.findBySql("select itemnum,numusage from gq_prlinechange where id='" + id1 + "'");
//                    if (CollectionUtils.isNotEmpty(bySql1)){
//                        for (int i=0;i<bySql1.size();i++){
//                            String itemnum = MapUtils.getString(bySql1.get(i), "itemnum");
//                            Float numusage1 = MapUtils.getFloat(bySql1.get(i), "numusage");//占用量
//                            String stu="科研管理";
//                            List<Map<String, Object>> bySql3 = handlerService.findBySql("select sum(a.numusage) as numusage from gq_prlinechange a where a.itemnum='" + itemnum + "' and (a.subjectno='" + subjectno + "' or a.subjectno='" + stu + "') and prcid='"+prcid+"'");
//                            Float numusage=(float)0.00;
//                            if (CollectionUtils.isNotEmpty(bySql3)){
//                                numusage = MapUtils.getFloat(bySql3.get(0), "numusage");
//                            }
//                            List<Map<String, Object>> bySql2 = handlerService.findBySql("SELECT \n" +
//                                    "    SUM(a.avblbalance) - "+numusage+" AS avblbalance \n" +
//                                    "FROM \n" +
//                                    "    gq_invbalances a \n" +
//                                    "WHERE \n" +
//                                    "    a.itemnum = '" + itemnum + "' \n" +
//                                    "    AND (a.subjectno = '" + subjectno + "' OR a.subjectno = '" + stu + "')\n");
//                            if (CollectionUtils.isNotEmpty(bySql2)){
//                                Float avblbalance = MapUtils.getFloat(bySql2.get(0), "avblbalance");
//                                if (numusage1==null){
//                                    numusage1=(float)0.00;
//                                }
//                                if (avblbalance==null){
//                                    avblbalance=(float)0.00;
//                                }
//                                avblbalance=avblbalance+numusage1;
//
//                                //更改采购申请明细行每个id下面的库存可用数量
//                                handlerService.updateBySql("update gq_prlinechange set avblbalance ="+avblbalance+" where id='"+id1+"' and prcid='"+prcid+"'");
//                            }
//                        }
//                    }
//
//
//                }
//            }
//        }
//
//    }
//}
